package com.ly.lypopupwindowdemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.app.hubert.library.Controller;
import com.app.hubert.library.HighLight;
import com.app.hubert.library.NewbieGuide;
import com.app.hubert.library.OnGuideChangedListener;
import com.ly.lypopupwindowdemo.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    Button start_pop, custom_view;

    @BindView(R.id.id_butterknife)
    Button butterknife;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ButterKnife.bind(this);

        start_pop = (Button) findViewById(R.id.start_pop);
        start_pop.setOnClickListener(this);
        custom_view = (Button) findViewById(R.id.custom_view);
        custom_view.setOnClickListener(this);
        findViewById(R.id.messagecenter).setOnClickListener(this);

        findViewById(R.id.service_study).setOnClickListener(this);
        findViewById(R.id.jump).setOnClickListener(this);
        findViewById(R.id.singleormulti).setOnClickListener(this);
        findViewById(R.id.designPattern).setOnClickListener(this);
        findViewById(R.id.nested).setOnClickListener(this);
        //.setBackgroundColor(Color.YELLOW)
        //.resetLabel("guide1");
        //.remove();移除引导层
        //.setEveryWhereCancelable(false)
        NewbieGuide.with(this)//传入activity
                .setLabel("guide1")//设置引导层标示，必传！否则报错
                .addHighLight(start_pop, HighLight.Type.RECTANGLE)//添加需要高亮的view
                .setLayoutRes(R.layout.view_guide)//自定义的提示layout，不要添加背景色，引导层背景色通过setBackgroundColor()设置
                .alwaysShow(true)
                .setOnGuideChangedListener(new OnGuideChangedListener() {
                    @Override
                    public void onShowed(Controller controller) {
                        //引导层显示
                        //Toast.makeText(MainActivity.this, "引导层显示", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onRemoved(Controller controller) {
                        //引导层消失
                        // Toast.makeText(MainActivity.this, "第一个引导层消失", Toast.LENGTH_SHORT).show();


                        NewbieGuide.with(MainActivity.this)//传入activity
                                .setLabel("guide2")//设置引导层标示，必传！否则报错
                                .addHighLight(custom_view, HighLight.Type.RECTANGLE)//添加需要高亮的view
                                .setLayoutRes(R.layout.view_guide)//自定义的提示layout，不要添加背景色，引导层背景色通过setBackgroundColor()设置
                                .alwaysShow(true)
                                .setOnGuideChangedListener(new OnGuideChangedListener() {
                                    @Override
                                    public void onShowed(Controller controller) {

                                        //Toast.makeText(MainActivity.this, "第二个蒙层显示", Toast.LENGTH_SHORT).show();
                                    }

                                    @Override
                                    public void onRemoved(Controller controller) {
                                        // Toast.makeText(MainActivity.this, "第二个引导层消失", Toast.LENGTH_SHORT).show();
                                    }
                                })
                                .show();
                    }
                })
                .show();//直接显示引导层


        findViewById(R.id.MD_study).setOnClickListener(this);
        findViewById(R.id.id_sqlite).setOnClickListener(this);
        findViewById(R.id.xnyh).setOnClickListener(this);
        findViewById(R.id.superTextView).setOnClickListener(this);
        findViewById(R.id.viewflipper).setOnClickListener(this);
        findViewById(R.id.WebView).setOnClickListener(this);
        findViewById(R.id.camera).setOnClickListener(this);
        findViewById(R.id.dialog).setOnClickListener(this);
        findViewById(R.id.id_study_pop).setOnClickListener(this);
        findViewById(R.id.id_sdcard).setOnClickListener(this);
        findViewById(R.id.id_viewpager).setOnClickListener(this);
        findViewById(R.id.id_jiexi).setOnClickListener(this);
        findViewById(R.id.id_detail).setOnClickListener(this);
        findViewById(R.id.id_per).setOnClickListener(this);
        findViewById(R.id.id_shape).setOnClickListener(this);
        findViewById(R.id.id_donghua).setOnClickListener(this);
        findViewById(R.id.id_shejimoshi).setOnClickListener(this);
        findViewById(R.id.id_multimedia).setOnClickListener(this);
        findViewById(R.id.id_fragment).setOnClickListener(this);
        findViewById(R.id.id_refresh).setOnClickListener(this);
        findViewById(R.id.id_duandian).setOnClickListener(this);
        Button btn = (Button) findViewById(R.id.id_intent_btn);
        findViewById(R.id.ijk).setOnClickListener(this);
        findViewById(R.id.broadcast).setOnClickListener(this);
        findViewById(R.id.selectordemo).setOnClickListener(this);

        findViewById(R.id.id_mytoast).setOnClickListener(this);

        findViewById(R.id.btn0).setOnClickListener(this);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(MainActivity.this, SecondActivity.class);
                intent.putExtra("gender", 1);
                intent.putExtra("name", "liying");
                startActivity(intent);
            }
        });

        Button btn_bundle = (Button) findViewById(R.id.id_bundle_btn);
        btn_bundle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //创建Bundle对象
                Bundle mBundle = new Bundle();
                //往bundle里面put值
                mBundle.putString("name", "周杰伦");
                mBundle.putString("gender", "男");
                mBundle.putBoolean("isStar", true);
                mBundle.putInt("height", 180);
                //创建Intent
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                //注意是putExtras()
                intent.putExtras(mBundle);
                startActivity(intent);
            }
        });


        Button forResult_btn = (Button) findViewById(R.id.id_forResult_btn);
        forResult_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                intent.putExtra("msg1", "你好我是A");
                startActivityForResult(intent, 666);//666 是requestCode 可以理解为一个标识，要>=0
            }
        });

        Button start_webview = (Button) findViewById(R.id.start_webview_btn);
        start_webview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyWebViewActivity.startWebView(MainActivity.this, "百度", "http://www.baidu.com");
            }
        });
    }

    private static final String TAG = "MainActivity";

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case 666:
                Bundle bundle = data.getExtras();
                String str2 = bundle.getString("msg2");
                String phone = bundle.getString("phone");
                Log.e(TAG, "onActivityResult: 收到SecondActivity的值==" + str2 + ", phone =" + phone);
                break;
            default:
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.start_pop:
                startActivity(new Intent(MainActivity.this, Main2Activity.class));
                break;
            case R.id.custom_view:
                //自定义控件
                startActivity(new Intent(MainActivity.this, CustomViewActivity.class));
                break;
            case R.id.MD_study:
                startActivity(new Intent(MainActivity.this, MDStudyActivity.class));
                break;
            case R.id.xnyh:
                //android性能优化
                startActivity(XingNengYouHuaActivity.class);
                break;
            case R.id.superTextView:
                //superTextView
                startActivity(SuperTextViewActivity.class);
                break;
            case R.id.viewflipper:
                //仿淘宝滚动广告
                startActivity(ViewFlipperActivity.class);
                break;
            case R.id.WebView:
                //WebView学习
                startActivity(WebViewStudyActivty.class);
                break;
            case R.id.btn0:

                //知识点查看
                startActivity(PointActivity.class);
                break;
            case R.id.camera:
                //相机相册
                startActivity(CameraActivity.class);
                break;
            case R.id.dialog:
                startActivity(DialogActivity.class);
                break;
            case R.id.id_study_pop:
                //学习自定义popupwindow
                //http://www.jianshu.com/p/799dbb86f908
                startActivity(StudyPopup.class);
                break;
            case R.id.id_sdcard:
                //sdcard图片的读取和写入
                startActivity(SDCardActivity.class);

                break;
            case R.id.id_viewpager:
                //学习viewpager
                startActivity(ViewPagerStudyActivity.class);
                break;
            case R.id.id_jiexi:
                startActivity(ParseActivity.class);
                break;
            case R.id.id_detail:
                //详情页面学习
                startActivity(DetailActivity.class);
                break;
            case R.id.id_per:
                //andorid6.0权限学习
                startActivity(PermissionStudy.class);
                break;
            case R.id.id_shape:
                //shape学习
                startActivity(ShapeDemoActivity.class);
                break;
            case R.id.id_donghua:
                //Android 动画学习
                startActivity(DongHuaDemoActivity.class);
                break;
            case R.id.id_duandian:
                //断点续传

                break;
            case R.id.id_shejimoshi:
                //设计模式

                break;
            case R.id.id_mytoast:
                //自定义toast
                startActivity(MyToastActivity.class);
                break;
            case R.id.id_multimedia:
                //Android 多媒体学习
                startActivity(MultimediaActivity.class);
                break;
            case R.id.id_fragment:
                //fragment学习
                startActivity(FragmentStudyActivity.class);
                break;
            case R.id.id_refresh:
                //SwipeToLoadRefresh学习
                startActivity(RefreshLibraryDemo.class);
                break;
            case R.id.id_sqlite:
                //数据库学习
                startActivity(SQLiteDemoActivity.class);
                break;
            case R.id.ijk:
                startActivity(StudyPopup.class);
                break;
            case R.id.broadcast:
                startActivity(BroadcastStudyActivity.class);
                break;
            case R.id.service_study:
                //Service学习
                startActivity(ServiceTestActivity.class);
                break;
            case R.id.jump:
                startActivity(JumpActivity.class);
                break;
            case R.id.singleormulti:
                //列表单选多选问题
                startActivity(SingleActivity.class);
                break;
            case R.id.selectordemo:
                startActivity(SelectorDemoActivity.class);
                break;
            case R.id.designPattern:
                //设计模式
                startActivity(DesignPatternActivity.class);
                break;
            case R.id.messagecenter:
                //消息中心，列表多选，批量管理，设置已读，删除，全选
                startActivity(MessageCenterActivity.class);
                break;
            case R.id.nested:
                //NestedScollView机制
                startActivity(NestedScrollDemoActivity.class);
                break;
            default:
                break;
        }
    }

    @OnClick(R.id.id_butterknife)
    public void ButterKnifeDemo() {
        startActivity(ButterKnifeDemoActivity.class);
    }

    private void startActivity(Class c) {
        Intent intent = new Intent(this, c);
        startActivity(intent);
    }

}
